package com.jchy.renderit.core;
 
public class Dir
{
    public double dx, dy, dz;
    
    public Dir()
    {
        dx=0.0; dy=0.0; dz=0.0;
    }

    public Dir(double inx, double iny, double inz)
    {
        dx=inx; dy=iny; dz=inz;
    }    

    public double length()
    {
        double result = Math.sqrt(dx*dx+dy*dy+dz*dz);
        return result;   
    }

    public void normalize()
    {
        double len = this.length();
        dx/=len;
        dy/=len;
        dz/=len;
    }

    public Dir cross(Dir indir)
    {
         Dir result = new Dir();
         result.dx = dy*indir.dz-dz*indir.dy;
         result.dy = dz*indir.dx-dx*indir.dz;
         result.dz = dx*indir.dy-dy*indir.dx;
         return result;
    }

    public static double dot(Dir a, Dir b)
    {
        double result;
        result=a.dx*b.dx + a.dy*b.dy + a.dz*b.dz;
        return result;
    }

    public static Dir add(Dir a, Dir b)
    {  
        Dir result = new Dir();
        result.dx = a.dx + b.dx;
        result.dy = a.dy + b.dy;
        result.dz = a.dz + b.dz;        
        return result;
    }

    public String toString()
    {
        return "<" + dx + ", " + dy + ", " + dz + ">";
    }

}
